package com.xiaoyun.lzg.strategy.manager;

import cn.hutool.core.util.ZipUtil;
import com.xiaoyun.lzg.controller.UserContext;
import com.xiaoyun.lzg.strategy.SuffixStrategy;
import com.xiaoyun.lzg.strategy.SuffixType;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ZIPModel extends SuffixStrategy {

    @Override
    public Object marker(String name, InputStream is) {
        String[] str = name.split("\\.");
        File outFile = new File(getFreeMarkerUtil().getTempName(str[0]));
        ZipUtil.unzip(is, outFile, null);
        List<Map<String, Object>> result = mapSave(outFile);

//        String msg = UserContext.get();
//        UserContext.remove();
//        root.put("errorMsg", msg);

        return result;
    }

    @Override
    public String getType() {
        return SuffixType.ZIP;
    }

}
